/**
 * 订阅事件 self 指定this 
 */
var events = {};

function on(name, self, callback) {
    var tuple = [self, callback],
        callbacks = events[name];
    if (Array.isArray(callbacks)) {
        callbacks.push(tuple)
    } else {
        events[name] = [tuple]
    }
}

function remove(name, self) {
    var callbacks = events[name];
    if (Array.isArray(callbacks)) {
        events[name] = callbacks.filter((tuple) => {
            return tuple[0] != self;
        })
    }
}

function emit(name, data) {
    var callbacks = events[name];
    if (Array.isArray(callbacks)) {
        callbacks.map((tuple) => {
            var self = tuple[0],
                callback = tuple[1];
            callback.call(self, data)
        })
    }
}